const getDefaultState = () => {
  return {
    currentSelectionType: null, // footer底部当前选择的类型
    currentSelectionElement: null, // 当前选中的元素
    fontList: {}, // 字体列表
    userInfo: {},
    templateDetail: null,
    showTextFlag: false, // 是否显示修改文字,
    showXinYinFlag: false, // 是否显示谐音框
    itemList: [],
    currentChangeType: 'changeText', // 谐音头像更换类型
  }
}

const state = getDefaultState();

const mutations = {
  SET_CURRENT_SELECTION_TYPE: (state, currentSelectionType) => {
    state.currentSelectionType = currentSelectionType;
  },
  SET_CURRENT_SELECTION_ELEMENT: (state, currentSelectionElement) => {
    state.currentSelectionElement = currentSelectionElement;
  },
  SET_FONT_LIST: (state, font) => {
    state.fontList[font] = font;
  },
  SET_TEMPLATE_DETAIL: (state, templateDetail) => {
    state.templateDetail = templateDetail;
  },
  SET_SHOW_TEXT_FALG: (state, showTextFlag) => {
    state.showTextFlag = showTextFlag;
  },
  SET_ITEM_LIST: (state, itemList) => {
    state.itemList = itemList;
  },
  SET_SHOW_XIEYIN_FALG: (state, showXinYinFlag) => {
    state.showXinYinFlag = showXinYinFlag;
  },
  SET_CURRENT_CHANGE_TYPE: (state, currentChangeType) => {
    state.currentChangeType = currentChangeType;
  }
}

const actions = {

  // 当前选择的类型
  async setCurrentSelectionType ({ commit }, currentSelectionType) {
    commit('SET_CURRENT_SELECTION_TYPE', currentSelectionType);
  },

  // 当前选中的原素
  async setCurrentSelectionElement ({ commit }, currentSelectionElement) {
    commit('SET_CURRENT_SELECTION_ELEMENT', currentSelectionElement);
  },

  // 设置字体列表
  async setFontList ({ commit }, fontList) {
    commit('SET_FONT_LIST', fontList);
  },

  // 设置
  async setTemplateDetail ({ commit }, templateDetail) {
    commit('SET_TEMPLATE_DETAIL', templateDetail);
  },

  // 设置显示文字
  async setShowTetxFlag ({ commit }, showTextFlag) {
    commit('SET_SHOW_TEXT_FALG', showTextFlag);
  },

  // 设置显示文字
  async setShowXieYinFlag ({ commit }, showXinYinFlag) {
    commit('SET_SHOW_XIEYIN_FALG', showXinYinFlag);
  },

  // 设置列表
  async setItemList ({ commit }, itemList) {
    commit('SET_ITEM_LIST', itemList);
  },

  // 设置更换类型
  async setCurrentChangeType ({ commit }, currentChangeType) {
    commit('SET_CURRENT_CHANGE_TYPE', currentChangeType);
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

